﻿@model AMC.SubstitutionCache.ViewModel.IndexViewModel
           
@{
    Layout.Title = T("Substitution Cache Settings");
}
@using (Html.BeginFormAntiForgeryPost()) {
    @Html.ValidationSummary()
    <div class="manage">@Html.ActionLink(T("Evict All").ToString(), "EvictAll", new { Area = "AMC.SubstitutionCache", Controller = "Admin" }, new { @class = "button primaryAction", itemprop = "UnsafeUrl" })</div>
}
<h2>@T("Settings")</h2>
@using (Html.BeginFormAntiForgeryPost())
{
    @Html.ValidationSummary()
    
    <fieldset>
        <label>@T("Post Transform")</label>
        @Html.CheckBoxFor(m => m.DoTransformOnRedirect) <label for="@Html.FieldIdFor(m => m.DoTransformOnRedirect)" class="forcheckbox">@T("Do Url Transform On Redirect / Post")</label>
        <span class="hint">@T("When checked, POST and redirects will have a unique querystring appended to bypass cache.")</span>

    </fieldset>
    <fieldset>
        <label>@T("Default Duration")</label>
        @Html.TextBoxFor(m => m.DefaultCacheDurationSeconds, new { @class = "text small" })
        <span class="hint">@T("Duration in seconds. 0 to disable default caching on substitutions.")</span>
    </fieldset>
    <fieldset>
        <label>@T("Excluded Shape Types")</label>
        @Html.TextBoxFor(m => m.ExcludedShapeTypes, new { @class = "text large" })
        <span class="hint">@T("Comma-separated list of Shape Types to always ignore for substitution caching.")</span>
    </fieldset>
    <button class="primaryAction" type="submit">@T("Save")</button>
}

<hr style="margin: 20px 0"/>
<h2>@T("Statistics")</h2>

    @foreach (var cacheItem in Model.Statistics.CacheItems)
    {
        var count = cacheItem.Substitutions.Count();
        <table class="items">
            <thead>
                <tr>
                    <th width="50%">@T("Shape")</th>
                    <th width="20%">@T("Substitutions")</th>
                    <th width="30%">@T("Urls")</th>

                </tr>
            </thead>
            <tr>
                <td>@cacheItem.ShapeDescription</td>
                <td>@count</td>
                <td>
                    @foreach (var url in cacheItem.Urls)
                    {
                        <a href="@url" target="_blank">@Html.Ellipsize(url, 100)</a><br />
                    }
                    @if (cacheItem.MoreUrlCount > 0)
                    {
                        <span class="hint">Plus @cacheItem.MoreUrlCount more...</span>
                    }
                </td>
            </tr>

            @if (count > 0)
            {
            <tr style="background: transparent">
                <td colspan="3">
                    <table class="items">
                        <thead>
                            <tr>
                                <th width="40%">@T("Substitution Cache Key")</th>
                                <th width="20%">@T("Cached On")</th>
                                <th width="20%">@T("Valid Until")</th>
                                <th width="20%">&nbsp;</th>
                            </tr>
                        </thead>
                        @foreach (var substitution in cacheItem.Substitutions)
                        {
                            <tr>
                                <td><span title="@substitution.CacheKey">@Html.Ellipsize(@substitution.CacheKey, 50)</span></td>
                                <td>@Display.DateTimeRelative(DateTimeUtc: substitution.CachedOnUtc)</td>
                                <td>@substitution.ValidUntilUtc.ToLocalTime()</td>
                                <td>@Html.ActionLink(T("Evict").Text, "Evict", new { Area = "AMC.SubstitutionCache", Controller = "Admin", cacheKey = substitution.CacheKey })</td>
                            </tr>
                        }
                    </table>
                </td>
            </tr>

            }
        </table>
    }


@Display(Model.Statistics.Pager)
